package org.testing;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class FileLogger {
	private FileWriter	wr;
	public FileLogger(String file_name) throws IOException {
		wr = new FileWriter(file_name,true);
	}
	
	public void logLogin(User user) throws IOException {
		Calendar cal = new GregorianCalendar();
		wr.write(new SimpleDateFormat().format(cal.getTime()));
		wr.write(" ");
		wr.write(user.getName() + " logged to system");
		wr.write("\r\n");
		wr.flush();
	} 
	
	public void logLogout(User user) throws IOException {
		Calendar cal = new GregorianCalendar();
		wr.write(new SimpleDateFormat().format(cal.getTime()));
		wr.write(" ");
		wr.write(user.getName() + " unlogged");
		wr.write("\r\n");
		wr.flush();
	}
	
	public void logStartTest(User user) throws IOException {
		Calendar cal = new GregorianCalendar();
		wr.write(new SimpleDateFormat().format(cal.getTime()));
		wr.write(" ");
		wr.write(user.getName() + " started test");
		wr.write("\r\n");
		wr.flush();
	}
	
	public void logTestFinished(User user) throws IOException {
		Calendar cal = new GregorianCalendar();
		wr.write(new SimpleDateFormat().format(cal.getTime()));
		wr.write(" ");
		wr.write(user.getName() + " finished test");
		wr.write("\r\n");
		wr.flush();
	}
}
